#define _CRT_SECURE_NO_WARNINGS 1
class Solution {
public:
    int subarrayBitwiseORs(vector<int>& arr) {
        int n = arr.size(), max = 0;
        for (auto i : arr) max |= i;
        vector<int> dp(n);
        unordered_map<int, int> hash;
        dp[0] = arr[0], hash[arr[0]];
        for (int i = 1; i < n; i++)
        {
            if (arr[i] == arr[i - 1]) continue;
            for (int j = i; j >= 0; j--)
            {
                if (i == j) dp[j] = arr[i];
                else dp[j] = arr[i] | dp[j];
                if (hash.count(dp[j]) == 0) hash[dp[j]];
                if (dp[j] == max) break;
            }
        }
        return hash.size();
    }
};